<%@ page import="com.party.core.model.system.TargetType" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="../include/tag.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<head>
	<title>${project == null ? '创建' : '编辑'}显示表单项</title>
	<%@include file="../include/commonFile.jsp" %>
	<link rel="stylesheet" href="${ctx}/css/common/list.css">
	<link rel="stylesheet" href="${ctx}/css/ui/activity/publish_form.css">
	<style>
		.add-form-content {
			max-width: inherit;
		}
		.add-form-content .form-inner{
			margin-right: 50px;
		}
		.form-tip {
			float: left;
			margin-right: 10px;
			width: calc(100% - 110px);
		}
	</style>
</head><body>
<!--头部-->
<%@include file="../include/header.jsp" %>
<div class="index-outside">
	<%@include file="../include/sidebar.jsp" %>
	<!--内容-->
	<section>
		<div class="section-main">
			<!-- 正文请写在这里 -->
			<div class="add-form-content" style="padding-right: 15px;">
				<form id="myForm" class="layui-form mt20" method="post" action="${ctx}/member/membermgmt/xzgs/project/save.do">
					<input type="hidden" name="createBy" value="${createBy}">
					<fieldset class="border mb10">
						<legend>表单项目名</legend>
						<div class="form-inner">
							<div class="layui-form-item">
								<label class="layui-form-label">名称<span class="f-verify-red">*</span></label>
								<div class="layui-input-block">
									<input type="text" name="title" lay-verify="required" maxlength="35" placeholder="请输入项目名称" class="layui-input form-tip" value="${project.title}" style="width: 50%">
									<div class="layui-form-mid layui-word-aux">最多35字符</div>
									<input type="hidden" name="id" value="${project.id}"/>
								</div>
							</div>
						</div>
					</fieldset>
					<%@include file="customCreateForm.jsp" %>
					<div class="layui-form-item">
						<div class="layui-input-block">
							<a href="javascript:void(0)" class="layui-btn layui-btn-danger" lay-submit lay-filter="*">立即提交</a>
							<a href="${ctx}/member/membermgmt/list.do" class="layui-btn layui-btn-primary">取消</a>
						</div>
					</div>
				</form>
			</div>
		</div><!--底部-->
		<%@include file="../include/footer.jsp" %>
	</section>
</div>

<script type="text/javascript" src="${ctxStatic}/UEditor/ueditor.config.js"></script>
<script type="text/javascript" src="${ctxStatic}/UEditor/ueditor.all.js"></script>
<script type="text/javascript" src="${ctxStatic}/UEditor/myplugin/uploadCI.js"></script>
<script type="text/javascript" src="${ctxStatic}/UEditor/myplugin/uploadVideo.js"></script>
<!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
<!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
<script type="text/javascript" src="${ctxStatic}/UEditor/lang/zh-cn/zh-cn.js"></script>
<script>
    var ue = UE.getEditor('ueditor1');

    $(function () {
        layui.use(['form'], function () {
            var form = layui.form;

            form.render('checkbox');
            form.render('radio');
            form.render('select');

            //自定义验证规则
            form.verify({
                title: function (value) {
                    if (value == "") {
                        return '请填写项目名称';
                    }
                },
                picture: function (value) {
                    var checked = $("[name=showPicture]:checked").val();
                    if ((util.isValid(checked) && checked == "1") && value == "") {
                        return "请上传项目封面图";
                    }
                },
                remarks: function (value) {
                    if (value == "") {
                        return "请填写项目描述";
                    }
                },
                content: function (value) {
                    var content = $("#contentView").html();
                    if (content == "") {
                        return "请填写项目详情";
                    }
                }
            });

            //监听提交
            form.on('submit', function (data) {
                if (checkField()) {
                    txz.submitObject(data.elem, function (callBack) {
                        resetIndex();
                        var action = $("#myForm").attr("action");
                        $.post(action, $('#myForm').serialize(), function (res) {
                            typeof callBack === 'function' && callBack();
                            if (res.success) {
                                util.layerMsgSuccess("提交成功", function () {
                                    location.href = "${ctx}/member/membermgmt/list.do";
                                });
                            } else {
                                util.layerMsgError("提交失败")
                            }
                        });
                    })
                    return false;
                }
            });
            form.render('radio');
        });
        ue.addListener('ready', function () {
            this.setHeight(500);
            this.setContent($("#contentView").html());
        });
        ue.addListener('blur', function () {
            $("#contentView").html(ue.getContent());
        });

        $('#sel_pic_img').click(function () {
            txz.openSelImg({
                min: 1,
                max: 1,
                info: '建议尺寸：800x450',
                type: '<%=TargetType.GATHER_FORM.getCode()%>',
                cb: function (imgs) {
                    $('#cover-img').css('background-image', 'url(' + imgs[0].path + ')');
                    $('#pic').val(imgs[0].path);
                }
            })
        })
    })

    // 文本编辑器图片上传
    function uEditorUploadCI(editor) {
        txz.openSelImg({
            min: 1,
            type: '<%=TargetType.GATHER_FORM.getCode()%>',
            cb: function (imgs) {
                if (imgs.length) {
                    for (var i = 0, item; i < imgs.length; i++) {
                        item = imgs[i];
                        editor.focus();
                        editor.execCommand('inserthtml', item.htmlStr);
                    }
                }
            }
        })
    }

    function uEditorUploadCIVideo(editor) {
        txz.openSelVideo({
            min: 1,
            type: '<%=TargetType.GATHER_FORM.getCode()%>',
            cb: function (imgs) {
                if (imgs.length) {
                    for (var i = 0, item; i < imgs.length; i++) {
                        item = imgs[i];
                        editor.focus();
                        editor.execCommand('inserthtml', item.htmlStr);
                    }
                }
            }
        })
    }
</script>
<script type="text/javascript">
    txz.initHeader({
        nav:[{
            name: '会员管理',
            curr: true
        },{
            name: '设计表单',
            curr: true
        }],
        btns:[{
            name: '返回',
            icon: 'back',
            href: '${ctx}/member/membermgmt/list.do'
        }]
    });
</script>
</body>
</html>